package goleetcode

func edgeScore(edges []int) int {
	n := len(edges)
	points := make([]int64, n)
	for i, x := range edges {
		points[x] += int64(i)
	}
	maxPoints := int64(-1)
	res := -1
	for i := 0; i < n; i++ {
		if points[i] > maxPoints {
			maxPoints = points[i]
			res = i
		}
	}
	return res
}